package com.dhcc.bpm.modules.scf.service.HomePageService.HomePageImpl;

import com.dhcc.bpm.modules.scf.dto.*;
import com.dhcc.bpm.modules.scf.entity.HomePage.Aggregate.*;
import com.dhcc.bpm.modules.scf.entity.HomePage.ScfAggregateInfo;
import com.dhcc.bpm.modules.scf.entity.SelectEntity.RecyclingInByPayment;
import com.dhcc.bpm.modules.scf.entity.SelectEntity.RecyclingWeighByRenewableOut;
import com.dhcc.bpm.modules.scf.entity.SelectEntity.RenewableInByPayment;
import com.dhcc.bpm.modules.scf.entity.SelectEntity.RenewableOutByRenewableIn;
import com.dhcc.bpm.modules.scf.mapper.*;
import com.dhcc.bpm.modules.scf.service.HomePageService.IScfAggregateInfoService;
import com.dhcc.bpm.modules.scf.service.*;
import com.dhcc.bpm.modules.scf.vo.ScfContractInfoVO.ScfGetContractDetailsVO;
import com.dhcc.bpm.modules.scf.vo.ScfDriverInfoVO.ScfGetDriverDetailsVO;
import com.dhcc.bpm.modules.scf.vo.ScfFileAttachmentInfoVO.ScfFileAttachmentInfoVO;
import com.dhcc.bpm.modules.scf.vo.ScfInvoiceInfoVO.ScfGetInvoiceDetailsVO;
import com.dhcc.bpm.modules.scf.vo.ScfPaymentInfoVO.ScfGetPaymentDetailsVO;
import com.dhcc.bpm.modules.scf.vo.ScfRecyclingInInfoVO.ScfGetRecyclingInDetailsVO;
import com.dhcc.bpm.modules.scf.vo.ScfRecyclingWeighInfoVO.ScfGetRecyclingWeighDetailsVO;
import com.dhcc.bpm.modules.scf.vo.ScfRenewableInInfoVO.ScfGetRenewableInDetailsVO;
import com.dhcc.bpm.modules.scf.vo.ScfRenewableOutInfoVO.ScfGetRenewableOutDetailsVO;
import com.dhcc.bpm.modules.scf.vo.ScfSubjectBasicInfoVO.ScfGetSubjectDetailsVO;
import com.dhcc.bpm.modules.scf.vo.ScfTruckInfoVO.ScfGetTruckDetailsVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 四流合一详情查看服务类
 */
@Service
@Slf4j
public class ScfAggregateInfoServiceImpl implements IScfAggregateInfoService {

    /**
     * 主体mapper接口
     */
    @Autowired
    private ScfSubjectBasicInfoMapper scfSubjectBasicInfoMapper;
    /**
     * 主体service接口
     */
    @Autowired
    private IScfSubjectBasicInfoService scfSubjectBasicInfoService;

    /**
     * 司机mapper接口
     */
    @Autowired
    private ScfDriverInfoMapper scfDriverInfoMapper;
    /**
     * 司机service接口
     */
    @Autowired
    private IScfDriverInfoService scfDriverInfoService;

    /**
     * 车辆mapper接口
     */
    @Autowired
    private ScfTruckInfoMapper scfTruckInfoMapper;
    /**
     * 车辆service接口
     */
    @Autowired
    private IScfTruckInfoService scfTruckInfoService;

    /**
     * 合同mapper接口
     */
    @Autowired
    private ScfContractInfoMapper scfContractInfoMapper;
    /**
     * 合同service接口
     */
    @Autowired
    private IScfContractInfoService scfContractInfoService;

    /**
     * 再生入库mapper接口
     */
    @Autowired
    private ScfRenewableInInfoMapper scfRenewableInInfoMapper;
    /**
     * 再生入库service接口
     */
    @Autowired
    private IScfRenewableInInfoService scfRenewableInInfoService;

    /**
     * 再生出库mapper接口
     */
    @Autowired
    private ScfRenewableOutInfoMapper scfRenewableOutInfoMapper;
    /**
     * 再生出库service接口
     */
    @Autowired
    private IScfRenewableOutInfoService scfRenewableOutInfoService;

    /**
     * 利废过磅单Mapper接口
     */
    @Autowired
    private ScfRecyclingWeighInfoMapper scfRecyclingWeighInfoMapper;
    /**
     * 利废过磅单单service接口
     */
    @Autowired
    private IScfRecyclingWeighInfoService scfRecyclingWeighInfoService;

    /**
     * 利废入库单mapper接口
     */
    @Autowired
    private ScfRecyclingInInfoMapper scfRecyclingInInfoMapper;
    /**
     * 利废入库单service接口
     */
    @Autowired
    private IScfRecyclingInInfoService scfRecyclingInInfoService;

    /**
     * 支付回单mapper接口
     */
    @Autowired
    private ScfPaymentInfoMapper scfPaymentInfoMapper;
    /**
     * 支付回单service接口
     */
    @Autowired
    private IScfPaymentInfoService scfPaymentInfoService;

    /**
     * 发票mapper接口
     */
    @Autowired
    private ScfInvoiceInfoMapper scfInvoiceInfoMapper;
    /**
     * 发票service接口
     */
    @Autowired
    private IScfInvoiceInfoService scfInvoiceInfoService;

    /**
     * 四流合一查询详情方法
     *
     * @param recyclingInNum
     * @return
     */
    @Override
    public ScfAggregateInfo detailAggregateInfo(String recyclingInNum) {
        // new 一个四流对象
        ScfAggregateInfo scfAggregateInfo = new ScfAggregateInfo();
        // 1.开始获取整个流程中的信息
        // 1.1 从利废入库单号作为入口开始反推--从利废入库单可以获取到供销合同编号、利废过磅单号
        // 1.1.1 获取利废入库单号对应的利废入库单记录的RowId
        String selectRowIdByRecyclingInNum = scfRecyclingInInfoMapper.selectRowIdByRecyclingInNum(recyclingInNum);
        // 1.1.2 创建利废入库单DTO对象，并设置利废入库单记录的RowId
        ScfRecyclingInInfoDTO scfRecyclingInInfoDTO = new ScfRecyclingInInfoDTO();
        scfRecyclingInInfoDTO.setRowId(selectRowIdByRecyclingInNum);
        // 1.1.3 调用利废入库单service接口查询利废入库单详细信息
        ScfGetRecyclingInDetailsVO RecyclingInInfoDetails = scfRecyclingInInfoService.getDetails(scfRecyclingInInfoDTO);
        if (RecyclingInInfoDetails != null) {
            // 1.1.4 获取供销合同编号
            String contractNum = RecyclingInInfoDetails.getContractNum();
            // 1.1.4.1 获取供销合同编号并查询出供销合同详情
            String selectRowIdByContractNumgx = scfContractInfoMapper.selectRowIdByContractNum( RecyclingInInfoDetails.getContractNum()   ,RecyclingInInfoDetails.getOrgCode() );
            ScfContractInfoDTO gxscfContractInfo = new ScfContractInfoDTO();
            gxscfContractInfo.setRowId(selectRowIdByContractNumgx);
            ScfGetContractDetailsVO gxscfContractInfoServiceDetails = scfContractInfoService.getDetails(gxscfContractInfo);


            // 1.1.5 获取利废过磅单号
            String weighNum = RecyclingInInfoDetails.getWeighNum();
            // 1.1.5.1 获取利废过磅单编号并查询出利废过磅单详情
            String rowIdByWeighNum = scfRecyclingWeighInfoMapper.getRowIdByWeighNum(weighNum);
            ScfRecyclingWeighInfoDTO scfRecyclingWeighInfo = new ScfRecyclingWeighInfoDTO();
            scfRecyclingWeighInfo.setRowId(rowIdByWeighNum);


            // 1.2 通过上一步获取的利废过磅单号查询利废过磅单信息--从利废过磅单可以获取到再生出库单的单号数组
            List<RecyclingWeighByRenewableOut> recyclingWeighByRenewableOuts = scfRecyclingWeighInfoMapper.selectRecyclingWeighByRenewableOut(weighNum);


            // 1.3 通过上一步获取到的再生出库单的List单号集合、取出第一条
            RecyclingWeighByRenewableOut recyclingWeighByRenewableOut = recyclingWeighByRenewableOuts.get(0);
            // 1.4 获取第一条中的再生出库单号
            String renewableOutNum = recyclingWeighByRenewableOut.getRenewableOutNum();
            // 1.5 根据再生出库单号获取再生出库单编号，并查询再生出库单详情
            String rowIdByRenewableOutNum = scfRenewableOutInfoMapper.selectRowIdByRenewableOutNum(renewableOutNum);
            ScfRenewableOutInfoDTO scfRenewableOutInfo = new ScfRenewableOutInfoDTO();
            scfRenewableOutInfo.setRowId(rowIdByRenewableOutNum);
            ScfGetRenewableOutDetailsVO scfRenewableOutInfoServiceDetails = scfRenewableOutInfoService.getDetails(scfRenewableOutInfo);
            // 1.6 通过再生出库单查询再生出库单与再生入库单关系
            List<ScfGetRenewableInDetailsVO> renewableOutByRenewableIns = scfRenewableOutInfoMapper.selectRenewableOutByRenewableInt(renewableOutNum);
            // 1.6.1 通过上一步获取到的再生入库单的List单号集合、取出第一条
            ScfGetRenewableInDetailsVO renewableOutByRenewableIn = renewableOutByRenewableIns.get(0);
            // 1.6.2 获取第一条中的再生入库单单号
            String renewableInNum = renewableOutByRenewableIn.getRenewableInNum();
            // 1.7 获取再生入库单详情
            String rowIdByRenewableInNum = scfRenewableInInfoMapper.selectRowIdByRenewableInNum(renewableInNum);
            ScfRenewableInInfoDTO scfRenewableInInfo = new ScfRenewableInInfoDTO();
            scfRenewableInInfo.setRowId(rowIdByRenewableInNum);
            ScfGetRenewableInDetailsVO scfRenewableInInfoServiceDetails = scfRenewableInInfoService.getDetails(scfRenewableInInfo);
            // 1.8 再生入库单中获取采购合同编号
            String cgcontractNum = scfRenewableInInfoServiceDetails.getContractNum();
            String selectRowIdByContractNumcg = scfContractInfoMapper.selectRowIdByContractNum(scfRenewableInInfoServiceDetails.getContractNum() ,scfRenewableInInfoServiceDetails.getOrgCode());
            ScfContractInfoDTO cgscfContractInfo = new ScfContractInfoDTO();
            cgscfContractInfo.setRowId(selectRowIdByContractNumcg);
            ScfGetContractDetailsVO cgscfContractInfoServiceDetails = scfContractInfoService.getDetails(cgscfContractInfo);
            // 1.9 获取主体对象
            // 1.9.1 再生资源主体
            String partyANum = cgscfContractInfoServiceDetails.getPartyANum();
            ScfSubjectBasicInfoDTO scfSubjectBasicInfoRenewable = new ScfSubjectBasicInfoDTO();
            scfSubjectBasicInfoRenewable.setRowId(partyANum);
            // 1.9.2 供应商主体
            String partyBNum = cgscfContractInfoServiceDetails.getPartyBNum();
            ScfSubjectBasicInfoDTO scfSubjectBasicInfoOwner = new ScfSubjectBasicInfoDTO();
            scfSubjectBasicInfoOwner.setRowId(partyBNum);

            // 1.9.3 供销合同详情查询主体
            String partyANumgx = gxscfContractInfoServiceDetails.getPartyANum();
            String partyBNumgx = gxscfContractInfoServiceDetails.getPartyBNum();
            ScfSubjectBasicInfoDTO scfSubjectBasicInfoRecycling = new ScfSubjectBasicInfoDTO();
            // A
            scfSubjectBasicInfoRecycling.setRowId(partyANumgx);
            ScfGetSubjectDetailsVO scfSubjectBasicInfoServiceDetailsRecyclingA = scfSubjectBasicInfoService.getDetails(scfSubjectBasicInfoRecycling);
            // B
            scfSubjectBasicInfoRecycling.setRowId(partyBNumgx);
            ScfGetSubjectDetailsVO scfSubjectBasicInfoServiceDetailsRecyclingB = scfSubjectBasicInfoService.getDetails(scfSubjectBasicInfoRecycling);
            // 创建一个新的主体对象
            SubjectBasicInfo subjectInfo = new SubjectBasicInfo();
            if (scfSubjectBasicInfoServiceDetailsRecyclingA != null && scfSubjectBasicInfoServiceDetailsRecyclingA.getSubRole().equals("2")) {
                subjectInfo.setName(scfSubjectBasicInfoServiceDetailsRecyclingA.getSubName());
                subjectInfo.setRegisteredAddr(scfSubjectBasicInfoServiceDetailsRecyclingA.getRegisteredAddr());
                subjectInfo.setIdNum(scfSubjectBasicInfoServiceDetailsRecyclingA.getScCode());
                subjectInfo.setSubType(scfSubjectBasicInfoServiceDetailsRecyclingA.getSubType());
                subjectInfo.setFileAttachmentInfoVOS(scfSubjectBasicInfoServiceDetailsRecyclingA.getFileAttachmentInfoVOS());
            } else if (scfSubjectBasicInfoServiceDetailsRecyclingB != null && scfSubjectBasicInfoServiceDetailsRecyclingB.getSubRole().equals("2")) {
                subjectInfo.setName(scfSubjectBasicInfoServiceDetailsRecyclingB.getSubName());
                subjectInfo.setRegisteredAddr(scfSubjectBasicInfoServiceDetailsRecyclingB.getRegisteredAddr());
                subjectInfo.setIdNum(scfSubjectBasicInfoServiceDetailsRecyclingB.getScCode());
                subjectInfo.setSubType(scfSubjectBasicInfoServiceDetailsRecyclingB.getSubType());
                subjectInfo.setFileAttachmentInfoVOS(scfSubjectBasicInfoServiceDetailsRecyclingB.getFileAttachmentInfoVOS());
            }
            ScfGetRecyclingWeighDetailsVO scfRecyclingWeighInfoServiceDetail = scfRecyclingWeighInfoService.getDetail(scfRecyclingWeighInfo);
            if (scfRecyclingWeighInfoServiceDetail != null) {
                // 从利废过磅单中获取驾驶证号和车牌号
                String license = scfRecyclingWeighInfoServiceDetail.getLicense();
                String truckNum = scfRecyclingWeighInfoServiceDetail.getTruckNum();
                // 查询司机详情
                String selectRowIdByLicense = scfDriverInfoMapper.selectRowIdByLicense(license);
                ScfDriverInfoDTO scfDriverInfo = new ScfDriverInfoDTO();
                scfDriverInfo.setRowId(selectRowIdByLicense);
                ScfGetDriverDetailsVO scfDriverInfoServiceDetails = scfDriverInfoService.getDetails(scfDriverInfo);
                // 查询车辆详情
                String selectRowIdByTruckNum = scfTruckInfoMapper.selectRowIdByTruckNum(truckNum ,scfRecyclingWeighInfoServiceDetail.getOrgCode());
                ScfTruckInfoDTO scfTruckInfo = new ScfTruckInfoDTO();
                scfTruckInfo.setRowId(selectRowIdByTruckNum);
                ScfGetTruckDetailsVO scfTruckInfoServiceDetails = scfTruckInfoService.getDetails(scfTruckInfo);


                // 根据再生入库单获取对应的支付回单关联关系
                List<RenewableInByPayment> renewableInByPayments = scfRenewableInInfoMapper.selectRenewableInByPayment(renewableInNum);
                ScfGetPaymentDetailsVO fkScfPaymentInfoServiceDetail = new ScfGetPaymentDetailsVO();
                ScfGetInvoiceDetailsVO scfGetInvoiceDetailsVOCG = new ScfGetInvoiceDetailsVO();
                if (!renewableInByPayments.isEmpty()) {
                    RenewableInByPayment renewableInByPayment = renewableInByPayments.get(0);
                    String fkPaymentNum = renewableInByPayment.getPaymentNum();
                    String fkSelectRowIdBypaymentNum = scfPaymentInfoMapper.selectRowIdBypaymentNum(fkPaymentNum);
                    ScfPaymentInfoDTO fkScfPaymentInfo = new ScfPaymentInfoDTO();
                    fkScfPaymentInfo.setRowId(fkSelectRowIdBypaymentNum);
                    fkScfPaymentInfoServiceDetail = scfPaymentInfoService.getDetail(fkScfPaymentInfo);
                    // 获取是否关联发票标识
                    String isWithInvoice = fkScfPaymentInfoServiceDetail.getIsWithInvoice();
                    if (!isWithInvoice.equals("0")) {
                        // 根据付款回单获取对应的发票信息
                        String selectRowIdByPaymentNum = scfInvoiceInfoMapper.selectRowIdByPaymentNum(fkScfPaymentInfoServiceDetail.getPaymentNum());
                        ScfInvoiceInfoDTO skScfInvoiceInfo = new ScfInvoiceInfoDTO();
                        skScfInvoiceInfo.setRowId(selectRowIdByPaymentNum);
                        scfGetInvoiceDetailsVOCG = scfInvoiceInfoService.details(skScfInvoiceInfo);
                        log.info("采购发票详情:{}", scfGetInvoiceDetailsVOCG);
                    }
                }
                // 根据利废入库单获取对应的支付回单关联关系
                List<RecyclingInByPayment> recyclingInByPayments = scfRecyclingInInfoMapper.selectRecyclingByPayment(recyclingInNum);
                ScfGetPaymentDetailsVO skScfPaymentInfoServiceDetail = new ScfGetPaymentDetailsVO();
                ScfGetInvoiceDetailsVO scfGetInvoiceDetailsVOGX = new ScfGetInvoiceDetailsVO();
                if (!recyclingInByPayments.isEmpty()) {
                    RecyclingInByPayment recyclingInByPayment = recyclingInByPayments.get(0);
                    String skPaymentNum = recyclingInByPayment.getPaymentNum();
                    String skSelectRowIdBypaymentNum = scfPaymentInfoMapper.selectRowIdBypaymentNum(skPaymentNum);
                    ScfPaymentInfoDTO skScfPaymentInfo = new ScfPaymentInfoDTO();
                    skScfPaymentInfo.setRowId(skSelectRowIdBypaymentNum);
                    skScfPaymentInfoServiceDetail = scfPaymentInfoService.getDetail(skScfPaymentInfo);
                    // 获取是否关联发票标识
                    String isWithInvoice = skScfPaymentInfoServiceDetail.getIsWithInvoice();
                    if (!isWithInvoice.equals("0")) {
                        // 根据收款回单获取对应的发票信息
                        String selectRowIdByPaymentNum = scfInvoiceInfoMapper.selectRowIdByPaymentNum(skScfPaymentInfoServiceDetail.getPaymentNum());
                        ScfInvoiceInfoDTO skScfInvoiceInfo = new ScfInvoiceInfoDTO();
                        skScfInvoiceInfo.setRowId(selectRowIdByPaymentNum);
//                        log.info("发票RowId:{}", selectRowIdByPaymentNum);
                        scfGetInvoiceDetailsVOGX = scfInvoiceInfoService.details(skScfInvoiceInfo);
//                        log.info("供销发票详情:{}", scfGetInvoiceDetailsVOGX);
                    }
                }


                // 1.5整理所有数据存入到scfAggregateInfo对象中
                // 准备对象
                SubjectBasicInfo ownerSubject = new SubjectBasicInfo();
                SubjectBasicInfo renewableSubject = new SubjectBasicInfo();
                SubjectBasicInfo recyclingSubject = new SubjectBasicInfo();
                ContractInfo cgContract = new ContractInfo();
                ContractInfo gxContract = new ContractInfo();
                TransportInfo wlTransport = new TransportInfo();
                PaymentInfo typeIsFk = new PaymentInfo();
                PaymentInfo typeIsSK = new PaymentInfo();
//                供销  和采购
                InvoiceInfo scfInvoiceInfoGX = new InvoiceInfo();
                InvoiceInfo scfInvoiceInfoCG = new InvoiceInfo();
                // 开始补充各对象中的参数
                // 供应商主体对象
                ScfGetSubjectDetailsVO scfSubjectBasicInfoServiceDetailsOwner = scfSubjectBasicInfoService.getDetails(scfSubjectBasicInfoOwner);
                if (scfSubjectBasicInfoServiceDetailsOwner != null) {
                    ownerSubject.setName(scfSubjectBasicInfoServiceDetailsOwner.getSubName());
                    ownerSubject.setRegisteredAddr(scfSubjectBasicInfoServiceDetailsOwner.getRegisteredAddr());
                    ownerSubject.setSubType(scfSubjectBasicInfoServiceDetailsOwner.getSubType());
                    if (ownerSubject.getSubType().equals("2")) {
                        ownerSubject.setIdNum(scfSubjectBasicInfoServiceDetailsOwner.getScCode());
                    } else {
                        ownerSubject.setIdNum(scfSubjectBasicInfoServiceDetailsOwner.getIdNum());
                    }
                    ownerSubject.setFileAttachmentInfoVOS(scfSubjectBasicInfoServiceDetailsOwner.getFileAttachmentInfoVOS());

                }
                ScfGetSubjectDetailsVO scfSubjectBasicInfoServiceDetailsRenewable = scfSubjectBasicInfoService.getDetails(scfSubjectBasicInfoRenewable);
                if (scfSubjectBasicInfoServiceDetailsRenewable != null) {
                    // 再生资源主体对象
                    renewableSubject.setName(scfSubjectBasicInfoServiceDetailsRenewable.getSubName());
                    renewableSubject.setRegisteredAddr(scfSubjectBasicInfoServiceDetailsRenewable.getRegisteredAddr());
                    renewableSubject.setIdNum(scfSubjectBasicInfoServiceDetailsRenewable.getScCode());
                    renewableSubject.setSubType(scfSubjectBasicInfoServiceDetailsRenewable.getSubType());
                    renewableSubject.setFileAttachmentInfoVOS(scfSubjectBasicInfoServiceDetailsRenewable.getFileAttachmentInfoVOS());
                }


                // 利废企业主体对象
                recyclingSubject.setName(subjectInfo.getName());
                recyclingSubject.setRegisteredAddr(subjectInfo.getRegisteredAddr());
                recyclingSubject.setIdNum(subjectInfo.getIdNum());
                recyclingSubject.setSubType(subjectInfo.getSubType());
                recyclingSubject.setFileAttachmentInfoVOS(subjectInfo.getFileAttachmentInfoVOS());

                // 采购合同对象补充--cgscfContractInfoServiceDetails
                cgContract.setContractType(cgscfContractInfoServiceDetails.getContractType());
                cgContract.setNameA(cgscfContractInfoServiceDetails.getNameA());
                cgContract.setNameB(cgscfContractInfoServiceDetails.getNameB());
                cgContract.setContractNum(cgscfContractInfoServiceDetails.getContractNum());
                if (cgscfContractInfoServiceDetails.getAmount() != null) {
                    cgContract.setAmount(String.valueOf(cgscfContractInfoServiceDetails.getAmount()));
                }
                cgContract.setSignDate(cgscfContractInfoServiceDetails.getSignDate());
                cgContract.setFileAttachmentInfoVOS(cgscfContractInfoServiceDetails.getFileAttachmentInfoVOS());
                // 供销合同对象补充
                gxContract.setContractType(gxscfContractInfoServiceDetails.getContractType());
                gxContract.setNameA(gxscfContractInfoServiceDetails.getNameA());
                gxContract.setNameB(gxscfContractInfoServiceDetails.getNameB());
                gxContract.setContractNum(gxscfContractInfoServiceDetails.getContractNum());
                if (gxscfContractInfoServiceDetails.getAmount() != null) {
                    gxContract.setAmount(String.valueOf(gxscfContractInfoServiceDetails.getAmount()));
                }
                gxContract.setSignDate(gxscfContractInfoServiceDetails.getSignDate());
                gxContract.setFileAttachmentInfoVOS(gxscfContractInfoServiceDetails.getFileAttachmentInfoVOS());
                // 物流对象补充
                wlTransport.setDriverName(RecyclingInInfoDetails.getDriverName());
                wlTransport.setMobile(RecyclingInInfoDetails.getDriverMobile());
                wlTransport.setDriverRowIdByfileId(scfDriverInfoServiceDetails.getFileAttachmentInfoVOS());
                wlTransport.setTruckNum(RecyclingInInfoDetails.getTruckNum());
                wlTransport.setTruckColourNum(scfTruckInfoServiceDetails.getTruckColourNum());

                if (scfTruckInfoServiceDetails.getEmptyWeight() != null) {
                    wlTransport.setEmptyWeight(String.valueOf(scfTruckInfoServiceDetails.getEmptyWeight()));
                }

                if (scfTruckInfoServiceDetails.getLoadCapacity() != null) {
                    wlTransport.setLoadCapacity(String.valueOf(scfTruckInfoServiceDetails.getLoadCapacity()));
                }

                if (scfTruckInfoServiceDetails.getTotalWeight() != null) {
                    wlTransport.setFullWeight(String.valueOf(scfTruckInfoServiceDetails.getTotalWeight()));
                }

                wlTransport.setTruckRowIdByfileId(scfTruckInfoServiceDetails.getFileAttachmentInfoVOS());
                wlTransport.setGoodsNum(RecyclingInInfoDetails.getSpecName());
                wlTransport.setStartDate(scfRecyclingWeighInfoServiceDetail.getFullDate());
                wlTransport.setEndDate(scfRecyclingWeighInfoServiceDetail.getEmptyDate());
                wlTransport.setWarehouseInNum(scfRenewableInInfoServiceDetails.getRenewableInNum());
                wlTransport.setRenewableInIdByfileId(scfRenewableInInfoServiceDetails.getFileAttachmentInfoVOS());
                wlTransport.setWarehouseOutNum(scfRenewableOutInfoServiceDetails.getRenewableOutNum());

                wlTransport.setRenewableOutIdByfiledId(scfRenewableOutInfoServiceDetails.getFileAttachmentInfoVOS());
                wlTransport.setWeighNum(scfRecyclingWeighInfoServiceDetail.getWeighNum());
                wlTransport.setWeightIdByfileId(scfRecyclingWeighInfoServiceDetail.getFileAttachmentInfoVOS());
                wlTransport.setWarehouseEntNum(RecyclingInInfoDetails.getRecyclingInNum());

                List<ScfFileAttachmentInfoVO> mergeList= scfRenewableOutInfoServiceDetails.getFileAttachmentInfoVOS();
                mergeList.addAll(RecyclingInInfoDetails.getFileAttachmentInfoVOS()) ;
                wlTransport.setWarehouseEntByfileId( mergeList);
                // 付款回单对象补充
                typeIsFk.setPaymentType(fkScfPaymentInfoServiceDetail.getPaymentType());
                typeIsFk.setPayeeName(fkScfPaymentInfoServiceDetail.getPayeeName());
                typeIsFk.setPayeeAccno(fkScfPaymentInfoServiceDetail.getPayeeAccno());
                typeIsFk.setPayerName(fkScfPaymentInfoServiceDetail.getPayerName());
                typeIsFk.setPayerBank(fkScfPaymentInfoServiceDetail.getPayerBank());
                typeIsFk.setPayerAccno(fkScfPaymentInfoServiceDetail.getPayerAccno());
                if (fkScfPaymentInfoServiceDetail.getAmount() != null) {
                    typeIsFk.setAmount(String.valueOf(fkScfPaymentInfoServiceDetail.getAmount()));
                }
                typeIsFk.setChannel(fkScfPaymentInfoServiceDetail.getChannel());
                typeIsFk.setBankName(fkScfPaymentInfoServiceDetail.getBankName());
                typeIsFk.setFileAttachmentInfoVOS(fkScfPaymentInfoServiceDetail.getFileAttachmentInfoVOS());
                // 收款回单对象补充
                typeIsSK.setPaymentType(skScfPaymentInfoServiceDetail.getPaymentType());
                typeIsSK.setPayeeName(skScfPaymentInfoServiceDetail.getPayeeName());
                typeIsSK.setPayeeAccno(skScfPaymentInfoServiceDetail.getPayeeAccno());
                typeIsSK.setPayerName(skScfPaymentInfoServiceDetail.getPayerName());
                typeIsSK.setPayerBank(skScfPaymentInfoServiceDetail.getPayerBank());
                typeIsSK.setPayerAccno(skScfPaymentInfoServiceDetail.getPayerAccno());
                if (skScfPaymentInfoServiceDetail.getAmount() != null) {
                    typeIsSK.setAmount(String.valueOf(skScfPaymentInfoServiceDetail.getAmount()));
                }
                typeIsSK.setChannel(skScfPaymentInfoServiceDetail.getChannel());
                typeIsSK.setBankName(skScfPaymentInfoServiceDetail.getBankName());
                typeIsSK.setFileAttachmentInfoVOS(skScfPaymentInfoServiceDetail.getFileAttachmentInfoVOS());
                // 采购发票信息对象补充
                if (scfGetInvoiceDetailsVOCG != null && scfGetInvoiceDetailsVOCG.getInvoiceType()!=null) {
                    scfInvoiceInfoCG.setInvoiceType(scfGetInvoiceDetailsVOCG.getInvoiceType());
                    scfInvoiceInfoCG.setInvoicerName(scfGetInvoiceDetailsVOCG.getInvoicerName());
                    scfInvoiceInfoCG.setBuyerName(scfGetInvoiceDetailsVOCG.getBuyerName());
                    scfInvoiceInfoCG.setInvoiceCode(scfGetInvoiceDetailsVOCG.getInvoiceCode());
                    scfInvoiceInfoCG.setInvoiceNum(scfGetInvoiceDetailsVOCG.getInvoiceNum());
                    scfInvoiceInfoCG.setTaxRate(scfGetInvoiceDetailsVOCG.getTaxRate());
                    if (scfGetInvoiceDetailsVOCG.getGoodAmount() != null) {
                        scfInvoiceInfoCG.setGoodAmount(String.valueOf(scfGetInvoiceDetailsVOCG.getGoodAmount()));
                    }
                    if (scfGetInvoiceDetailsVOCG.getTaxAmount() != null) {
                        scfInvoiceInfoCG.setTaxAmount(String.valueOf(scfGetInvoiceDetailsVOCG.getTaxAmount()));
                    }
                    scfInvoiceInfoCG.setInvoiceDate(scfGetInvoiceDetailsVOCG.getInvoiceDate());
                    scfInvoiceInfoCG.setFileAttachmentInfoVOS(scfGetInvoiceDetailsVOCG.getFileAttachmentInfoVOS());
                }
                // 供销发票信息对象补充
                if (scfGetInvoiceDetailsVOGX != null && scfGetInvoiceDetailsVOGX.getInvoiceType()!=null) {
                    scfInvoiceInfoGX.setInvoiceType(scfGetInvoiceDetailsVOGX.getInvoiceType());
                    scfInvoiceInfoGX.setInvoicerName(scfGetInvoiceDetailsVOGX.getInvoicerName());
                    scfInvoiceInfoGX.setBuyerName(scfGetInvoiceDetailsVOGX.getBuyerName());
                    scfInvoiceInfoGX.setInvoiceCode(scfGetInvoiceDetailsVOGX.getInvoiceCode());
                    scfInvoiceInfoGX.setInvoiceNum(scfGetInvoiceDetailsVOGX.getInvoiceNum());
                    scfInvoiceInfoGX.setTaxRate(scfGetInvoiceDetailsVOGX.getTaxRate());
                    if (scfGetInvoiceDetailsVOGX.getGoodAmount() != null) {
                        scfInvoiceInfoGX.setGoodAmount(String.valueOf(scfGetInvoiceDetailsVOGX.getGoodAmount()));
                    }
                    if (scfGetInvoiceDetailsVOGX.getTaxAmount() != null) {
                        scfInvoiceInfoGX.setTaxAmount(String.valueOf(scfGetInvoiceDetailsVOGX.getTaxAmount()));
                    }
                    scfInvoiceInfoGX.setInvoiceDate(scfGetInvoiceDetailsVOGX.getInvoiceDate());
                    scfInvoiceInfoGX.setFileAttachmentInfoVOS(scfGetInvoiceDetailsVOGX.getFileAttachmentInfoVOS());
                }


                // 设置对象至scfAggregateInfo
                scfAggregateInfo.setOwnerSubject(ownerSubject);
                scfAggregateInfo.setRenewableSubject(renewableSubject);
//                利废企业主体对象
                scfAggregateInfo.setRecyclingSubject(recyclingSubject);
                scfAggregateInfo.setCgContract(cgContract);
                scfAggregateInfo.setGxContract(gxContract);
//                物流信息
                scfAggregateInfo.setWlTransport(wlTransport);
                scfAggregateInfo.setTypeIsFk(typeIsFk);
                scfAggregateInfo.setTypeIsSK(typeIsSK);
                scfAggregateInfo.setScfInvoiceInfoCG(scfInvoiceInfoCG);
                scfAggregateInfo.setScfInvoiceInfoGX(scfInvoiceInfoGX);
            }
        }
        return scfAggregateInfo;
    }
}
